package com.gaohe.web.controller.scp;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.scp.domain.CsCarSituation;
import com.gaohe.scp.service.ICsCarSituationService;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.common.core.page.TableDataInfo;

/**
 * 车况信息Controller
 *
 * @author liuxiangyu
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/scp/situation")
public class CsCarSituationController extends BaseController
{
    @Autowired
    private ICsCarSituationService csCarSituationService;
    // 通过carId查询查询车况信息------牛相善
//    @PreAuthorize("@ss.hasPermi('scp:situation:query')")
    @GetMapping(value = "/car/{carId}")
    public TableDataInfo getByCarId(@PathVariable("carId") Long carId)
    {
        List<CsCarSituation> list = csCarSituationService.selectCsCarSituationListByCarId(carId);
        return getDataTable(list);
    }
    /**
     * 查询车况信息列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:situation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsCarSituation csCarSituation)
    {
        startPage();
        List<CsCarSituation> list = csCarSituationService.selectCsCarSituationList(csCarSituation);
        return getDataTable(list);
    }

    /**
     * 导出车况信息列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:situation:export')")
    @Log(title = "车况信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsCarSituation csCarSituation)
    {
        List<CsCarSituation> list = csCarSituationService.selectCsCarSituationList(csCarSituation);
        ExcelUtil<CsCarSituation> util = new ExcelUtil<CsCarSituation>(CsCarSituation.class);
        util.exportExcel(response, list, "车况信息数据");
    }

    /**
     * 获取车况信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:situation:query')")
    @GetMapping(value = "/{situationId}")
    public AjaxResult getInfo(@PathVariable("situationId") Long situationId)
    {
        return success(csCarSituationService.selectCsCarSituationBySituationId(situationId));
    }

    /**
     * 新增车况信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:situation:add')")
    @Log(title = "车况信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsCarSituation csCarSituation)
    {
        return toAjax(csCarSituationService.insertCsCarSituation(csCarSituation));
    }

    /**
     * 修改车况信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:situation:edit')")
    @Log(title = "车况信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsCarSituation csCarSituation)
    {
        return toAjax(csCarSituationService.updateCsCarSituation(csCarSituation));
    }

    /**
     * 删除车况信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:situation:remove')")
    @Log(title = "车况信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{situationIds}")
    public AjaxResult remove(@PathVariable Long[] situationIds)
    {
        return toAjax(csCarSituationService.deleteCsCarSituationBySituationIds(situationIds));
    }
}
